<template>
  <el-card>
    <el-form inline label-width="80px" class="form-inline">
      <el-form-item label="一级属性">
        <el-select
          v-model="categoryStore.category1Id"
          @change="category1Change"
          :disabled="!!scene"
        >
          <el-option
            v-for="item in categoryStore.category1List"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级属性">
        <el-select
          v-model="categoryStore.category2Id"
          @change="category2Change"
          :disabled="!!scene"
        >
          <el-option
            v-for="item in categoryStore.category2List"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级属性">
        <el-select v-model="categoryStore.category3Id" :disabled="!!scene">
          <el-option
            v-for="item in categoryStore.category3List"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script setup lang="ts">
import { onMounted, onUnmounted } from 'vue'
import useCategoryStore from '@/store/modules/category'

defineProps(['scene'])

const categoryStore = useCategoryStore()

onMounted(() => {
  categoryStore.getCategory1()
})

const category1Change = () => {
  categoryStore.category2Id = ''
  categoryStore.category3Id = ''
  categoryStore.category3List = []
  categoryStore.getCategory2()
}
const category2Change = () => {
  categoryStore.category3Id = ''
  categoryStore.getCategory3()
}

onUnmounted(() => {
  categoryStore.$reset()
})
</script>
<script lang="ts">
export default {
  name: 'Category'
}
</script>
<style lang="scss" scoped>
.form-inline {
  :deep(.el-input) {
    --el-input-width: 220px;
  }
  :deep(.el-select) {
    --el-select-width: 220px;
  }
}
</style>
